package com.javaclimb.accounting.utils;

import java.io.Serializable;

//封装返回的统一格式的json数据

public class R implements Serializable {
    private static final int ok=200;
    private static final int error=500;

    private Integer status;//状态码200表示成功,500表示失败
    private String message;//提示信息
    private Object data;//服务端返回的数据

    //调用成功的情况
    public static R ok(){
        R r=new R();
        r.setStatus(ok);
        r.setMessage("查询成功");
        return r;
    }
    public static R ok(String message){
        R r = new R();
        r.setStatus(ok);
        r.setMessage(message);
        return r;
    }
    public static R ok(Object data){
        R r = new R();
        r.setStatus(ok);
        r.setMessage("查询成功");
        r.setData(data);
        return r;
    }
    public static R ok(String message,Object data){
        R r = new R();
        r.setStatus(ok);
        r.setMessage(message);
        r.setData(data);
        return r;
    }

    //调用失败的情况
    public static R fail(){
        R r = new R();
        r.setStatus(error);
        r.setMessage("查询失败");
        return r;
    }
    public static R fail(String message){
        R r = new R();
        r.setStatus(error);
        r.setMessage(message);
        return r;
    }


    public static int getOk() {
        return ok;
    }

    public static int getError() {
        return error;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
